import { Feedback } from '@/types';

const STORAGE_KEYS = {
  FEEDBACKS: 'aigls_feedbacks'
};

export const storage = {
  getFeedbacks(): Feedback[] {
    if (typeof window === 'undefined') return [];
    const stored = localStorage.getItem(STORAGE_KEYS.FEEDBACKS);
    return stored ? JSON.parse(stored) : [];
  },

  addFeedback(content: string): void {
    if (typeof window === 'undefined') return;
    const feedbacks = this.getFeedbacks();
    const newFeedback: Feedback = {
      id: Date.now().toString(),
      content,
      timestamp: Date.now()
    };
    feedbacks.push(newFeedback);
    localStorage.setItem(STORAGE_KEYS.FEEDBACKS, JSON.stringify(feedbacks));
  },

  clearFeedbacks(): void {
    if (typeof window === 'undefined') return;
    localStorage.removeItem(STORAGE_KEYS.FEEDBACKS);
  }
};